MLBA Tools & Lab Setup
03.03.2025
Install GitHub Desktop app to help you with using GitHub. Additionally, you can see our FAQ for obtaining professional accounts.
{here} package for easy file path management within projects.renv)renv is a package management tool that helps you manage the packages used in an R project.renv)renv project with renv::init().renv::restore() to install packages from the renv.lock file.renv::snapshot() to occasionally update your packages.renv::status() to see if the list in renv.lock needs updating.reticulate)reticulate)reticulate package in R.reticulate::use_python() or reticulate::use_condaenv() to specify the location of your python environment.reticulate::import() to import python modules in R.reticulate::py_run_string() to execute python code in R.{python} at the beginning of the code chunk.r.OBJECT_NAME.py$OBJECT_NAME.reticulate::r_to_py() and reticulate::py_to_r() to explicitly change between objects.
Modelling in pure Python
# load the required libraries
import statsmodels.api as sm
import pandas as pd
# Fit linear regression model to iris coming from R
X = r.iris[['Sepal.Width','Petal.Length','Petal.Width']]
y = r.iris['Sepal.Length']
X = sm.add_constant(X)
py_lm_fit = sm.OLS(y, X).fit()
#print regression results
print(py_lm_fit.summary())renv helps with managing packages in R, ensuring reproducibility, and making your work easier to share.reticulate allows you to use python in R and combine the strengths of both languages.Questions?
MLBA 2025